package org.xiaojinlong.playground;

import edu.princeton.cs.algs4.*;

import static edu.princeton.cs.algs4.StdDraw.*;
import static java.util.Arrays.*;

/**
 * @author Jin Long
 *         2016/3/5
 */
public class Draw {
    public static void main(String[] args) {
//        int n = 100;
//        StdDraw.setXscale(0, n);
//        StdDraw.setYscale(0, n*n);
//        StdDraw.setPenRadius(0.01);
//        for (int i = 1; i <= n; i++) {
//            point(i, i);
//            point(i, i*i);
//            point(i, i*Math.log(i));
//        }

//        int n = 50;
//        double[] a = new double[n];
//        for (int i = 0; i < n; i++) {
//            a[i] = StdRandom.uniform();
//        }
//        sort(a);
//        for (int i = 0; i < n; i++) {
//            double x = 1.0 * i / n;
//            double y = a[i] / 2.0;
//            double rw = 0.5 / n;
//            double rh = a[i] / 2.0;
//            filledRectangle(x, y, rw, rh);
//        }
        double xlo = Double.parseDouble(args[0]);
        double xhi = Double.parseDouble(args[1]);
        double ylo = Double.parseDouble(args[2]);
        double yhi = Double.parseDouble(args[3]);
        int t = Integer.parseInt(args[4]);

        Interval1D xinterval = new Interval1D(xlo, xhi);
        Interval1D yinterval = new Interval1D(ylo, yhi);
        Interval2D box = new Interval2D(xinterval, yinterval);
        box.draw();

        Counter counter = new Counter("hits");
        for (int i = 0; i < t; i++) {
            double x = Math.random();
            double y = Math.random();
            Point2D point = new Point2D(x, y);
            if (box.contains(point)) {
                counter.increment();
            } else {
                point.draw();
            }
        }

        StdOut.println(counter);
        StdOut.println(box.area());
    }
}
